package com.seele.tigerwallet.ui.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.seele.tigerwallet.R;
import com.seele.tigerwallet.model.MarketModel;
import com.seele.tigerwallet.model.UserInfo;
import com.seele.tigerwallet.ui.manager.GlideManager;
import com.seele.tigerwallet.ui.utils.TypefaceUtils;

public class SortAdapter extends BaseQuickAdapter<MarketModel, BaseViewHolder> {


    private OnSortClickLitener mLitener;

    public void setOnSortClickLitener(OnSortClickLitener litener) {
        this.mLitener = litener;

    }

    public interface OnSortClickLitener {
        void onTop(MarketModel item);

        void onUp(MarketModel item, int position);

        void onLower(MarketModel item, int position);
    }

    public SortAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final MarketModel item) {
        if (!TextUtils.isEmpty(item.symbol)) {
            helper.setText(R.id.token_name_tv, item.symbol);
        }

        TextView name = helper.getView(R.id.token_name_tv);
        TypefaceUtils.setCenturyGothicBold(name, mContext);



        TextView topView = helper.getView(R.id.sort_arrow_top_tx);
        TextView upView = helper.getView(R.id.sort_arrow_up_tx);
        TextView lowerView = helper.getView(R.id.sort_arrow_lower_tx);

        ImageView imageView = helper.getView(R.id.token_icon_img);

        GlideManager.loadUrl(mContext,item.id + "",imageView);

//        Glide.with(mContext).load(UserInfo.getUrl(item.id + "")).into(imageView);


        topView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != mLitener) {
                    mLitener.onTop(item);
                }
            }
        });
        upView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != mLitener) {
                    mLitener.onUp(item,helper.getLayoutPosition());
                }
            }
        });
        lowerView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != mLitener) {
                    mLitener.onLower(item,helper.getLayoutPosition());
                }
            }
        });
    }
}
